package com.rchou.sts.domain;

import static javax.persistence.GenerationType.IDENTITY;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;
import javax.persistence.Version;

import org.hibernate.annotations.Type;
import org.joda.time.DateTime;
import org.springframework.data.domain.Auditable;

@Entity
@Table(name = "level")
public class Level implements Auditable<String, Long>, Serializable
{
	@Id
	@GeneratedValue(strategy = IDENTITY)
	@Column(name = "ID")
	private Long id;
	@Version
	@Column(name = "VERSION")
	private int version;
	@Temporal(TemporalType.DATE)
	@Column(name = "SUBMIT_DATE")
	private Date submitDate;
	//private Long studentId;
	@Column(name = "LEVEL")
	private Integer level;
	
	// Audit field
	@Column(name = "CREATED_BY")
	private String createdBy;
	@Column(name = "CREATED_DATE")
	@Type(type="org.joda.time.contrib.hibernate.PersistentDateTime")
	private DateTime createdDate;
	@Column(name = "LAST_MODIFIED_BY")
	private String lastModifiedBy;
	@Column(name = "LAST_MODIFIED_DATE")
	@Type(type="org.joda.time.contrib.hibernate.PersistentDateTime")
	private DateTime lastModifiedDate;
		
	@ManyToOne
	@JoinColumn(name = "STUDENT_ID")
	private Student student;
	
	public Long getId() 
	{
		return id;
	}
	
	public void setId(Long id) 
	{
		this.id = id;
	}
	
	public int getVersion() 
	{
		return this.version;
	}
	
	public void setVersion(int version) 
	{
		this.version = version;
	}
	
	public Date getSubmitDate() 
	{
		return submitDate;
	}
	
	public void setSubmitDate(Date submitDate) 
	{
		this.submitDate = submitDate;
	}
	
	public Integer getLevel() 
	{
		return level;
	}

	public void setLevel(Integer level) 
	{
		this.level = level;
	}
	
	/*public Long getStudentId() 
	{
		return studentId;
	}
	
	public void setStudentId(Long studentId) 
	{
		this.studentId = studentId;
	}*/
	
	public Student getStudent() 
	{
		return this.student;
	}

	public void setStudent(Student student) 
	{
		this.student = student;
	}
	
	public String getCreatedBy() 
	{
		return createdBy;
	}

	public void setCreatedBy(String createdBy) 
	{
		this.createdBy = createdBy;
	}

	public DateTime getCreatedDate() 
	{
		return createdDate;
	}

	public void setCreatedDate(DateTime createdDate) 
	{
		this.createdDate = createdDate;
	}

	public String getLastModifiedBy() 
	{
		return lastModifiedBy;
	}

	public void setLastModifiedBy(String lastModifiedBy) 
	{
		this.lastModifiedBy = lastModifiedBy;
	}

	public DateTime getLastModifiedDate() 
	{
		return lastModifiedDate;
	}
	
	public void setLastModifiedDate(DateTime lastModifiedDate) 
	{
		this.lastModifiedDate = lastModifiedDate;
	}
	
	@Transient
	public boolean isNew() 
	{
		if (id == null) 
		{
			return true;
		} else 
		{
			return false;
		}
	}
	
	@Override
	public String toString() {
		return "Level [id=" + id + ", version=" + version
				+ ", submitDate=" + submitDate + ", level=" + level
				+ ", Create by: " + createdBy + ", Create date: " + createdDate
				+ ", Modified by: " + lastModifiedBy + ", Modified date: "
				+ lastModifiedDate + "]";
	}
}
